package util;

import dao.impl.CaseHistoryDaoImpl;

import java.util.Random;

/**
 * @Author:
 * @Date: 2020-04-30
 * @Description: @PACKAGE:util
 * @version: 1.0
 */
public class NumberCreateUtil {

    public static String chNumber(String door) {
        String number = null;
        CaseHistoryDaoImpl caseHistoryDao = new CaseHistoryDaoImpl();
        //210381   20200430        001   0001
        //地区码   单次就诊日期    科室   编号
        String loc = "210381";
        String date = DateUtil.getStringDateShort();
        String tv = loc + date + door;
        int identifier = caseHistoryDao.getByCaseHistoryIdLike(tv).size();
        number = tv + String.valueOf(identifier + 1);
        return number;
    }

    public static String chNumberRan() {
        String number = null;
        String n = "";
        String door = "";
        CaseHistoryDaoImpl caseHistoryDao = new CaseHistoryDaoImpl();
        Random random = new Random();
        door = Integer.toHexString(random.nextInt(9)).toUpperCase();

        //210381   20200430        001   0001
        //地区码   单次就诊日期    科室   编号
        String loc = "210381";
        String date = DateUtil.getStringDateShort().replace("-", "");
        String tv = loc + date + "00" + door;
        int identifier = caseHistoryDao.getByCaseHistoryIdLike(tv).size();
        if (identifier < 9) {
            n = "000" + String.valueOf(identifier + 1);
        } else if (identifier >= 9 && identifier < 99) {
            n = "00" + String.valueOf(identifier + 1);
        } else if (identifier >= 99 && identifier < 999) {
            n = "0" + String.valueOf(identifier + 1);
        }
        number = tv + n;
        return number;
    }
}